package com.shux.usermanager.action;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.shux.usermanager.biz.ISysRoleBiz;
import com.shux.usermanager.entity.SysRole;

/**
 **********************************************
 *  描述：
 * Simba.Hua
 * 2017年7月11日
 **********************************************
**/
@Controller
@RequestMapping("/usermanager")
public class SysRoleAction extends UserManagerBaseAction {
    private @Autowired ISysRoleBiz sysRoleBiz;
    @RequestMapping("/queryrole")
    @RequiresPermissions("role:query")
    public ModelAndView queryRole(){
       List<SysRole> rootSysRoles = sysRoleBiz.queryAllRootRole();
       ModelAndView mv = getModelAndView();
       mv.addObject("rootSysRoles", rootSysRoles);
       mv.addObject("currentRole",getCurrentRole());
       mv.setViewName("jsp/role/rolelist");
       return mv;
    }
    @RequestMapping("/queryRoleByParentId")
    public ModelAndView queryRoleByParentId(String roleId){
        List<SysRole> sysRoles = sysRoleBiz.querySysRoleByParentId(roleId);
        ModelAndView mv = getModelAndView();
        List<SysRole> rootSysRoles = sysRoleBiz.queryAllRootRole();
        mv.addObject("rootSysRoles", rootSysRoles);
        mv.addObject("sysRoles", sysRoles);
        mv.addObject("currentRole",new SysRole(roleId));
        mv.setViewName("jsp/role/rolelist");
        return mv;
    }
    @RequestMapping("/toAdd")
    @RequiresPermissions("role:add")
    public ModelAndView toAdd(){
        ModelAndView mv = getModelAndView();
        mv.addObject("msg","add");
        mv.setViewName("jsp/role/roleEdit");
        return mv;
    }
}
